package com.yu.boot.admin.service;

import com.github.pagehelper.PageHelper;
import com.lhy.commonweb.model.Page;
import com.lhy.commonweb.service.AbstractService;
import com.yu.boot.admin.mapper.CategoryMapper;
import com.yu.boot.admin.model.Category;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.common.Mapper;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Service
public class CategoryService extends AbstractService<Category, Integer> {
    public CategoryService(@Qualifier("categoryMapper") Mapper<Category> mapper) {
        super(mapper);
    }

    public Page<Category> listLike(int pageSize, int pageNumber, String sortColumn, Category category) {
        CategoryMapper categoryMapper = getMapper();
        int i = categoryMapper.searchCount(category);
        PageHelper.startPage(pageNumber, pageSize, sortColumn);
        List<Category> search = categoryMapper.search(category);
        return new Page<>(pageNumber, pageSize, i, search);
    }

    public List<Category> listCategory(Category bean) {
        CategoryMapper categoryMapper = getMapper();
        return categoryMapper.select(bean);
    }

    public int countCategoryByUserName(String username) {
        CategoryMapper categoryMapper = getMapper();
        return categoryMapper.selectCount(new Category().setParentName(username));
    }

    public int deleteByCover(String cover) {
        CategoryMapper categoryMapper = getMapper();
        Category category = new Category();
        category.setCover(cover);
        return categoryMapper.delete(category);
    }

}
